<template>
  <div class="error-view">
    <div class="error-content">
      <div class="error-icon">
        <el-icon><Warning v-if="errorCode === 403" /><Document v-else /></el-icon>
      </div>
      <h1 class="error-title">{{ getErrorTitle() }}</h1>
      <p class="error-message">{{ getErrorMessage() }}</p>
      <div class="error-actions">
        <el-button type="primary" @click="goHome">返回首页</el-button>
        <el-button @click="goBack">返回上一页</el-button>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { useRouter } from 'vue-router'
import { ElButton, ElIcon } from 'element-plus'
import { Warning, Document } from '@element-plus/icons-vue'

interface Props {
  errorCode?: number
}

const props = withDefaults(defineProps<Props>(), {
  errorCode: 404
})

const router = useRouter()

const getErrorTitle = () => {
  const titles = {
    403: '403 - 无权限访问',
    404: '404 - 页面不存在'
  }
  return titles[props.errorCode as keyof typeof titles] || '发生错误'
}

const getErrorMessage = () => {
  const messages = {
    403: '抱歉，您没有权限访问此页面。',
    404: '抱歉，您访问的页面不存在。'
  }
  return messages[props.errorCode as keyof typeof messages] || '发生了未知错误。'
}

const goHome = () => {
  router.push('/')
}

const goBack = () => {
  router.go(-1)
}
</script>

<style scoped>
.error-view {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f0f2f5;
}

.error-content {
  text-align: center;
  padding: 40px;
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.error-icon {
  font-size: 80px;
  color: #909399;
  margin-bottom: 20px;
}

.error-title {
  font-size: 24px;
  color: #303133;
  margin: 0 0 16px 0;
}

.error-message {
  font-size: 16px;
  color: #606266;
  margin: 0 0 30px 0;
}

.error-actions {
  display: flex;
  gap: 16px;
  justify-content: center;
}
</style>